Naudio - putting audio stream into values [-1,1]

Posted by denonth on Stack Overflow See other posts from Stack Overflow or by denonth
Published on 2012-03-21T10:52:36Z Indexed on 2012/03/21 11:29 UTC
Read the original article Hit count: 222

Filed under:
|
|
|
|

Hi all I need to put my audio stream into values of [-1,1].

Can someone tell me a good approach. I was reading byte array and float array from stream but I don't know what to do next.

Here is my code:

float[] bytes=new float[stream.Length];
            float biggest= 0;
            for (int i = 0; i < stream.Length; i++)
            {
                bytes[i] = (byte)stream.ReadByte();
                if (bytes[i] > biggest)
                {
                    biggest=bytes[i];
                }
            }

and I don't know how to put values into stream. Because byte is only positive values. And I need to have from [-1,1]

        for (int i = 0; i < bytes.Count(); i++)
        {
            bytes[i] = (byte)(bytes[i] * (1 / biggest));
        }

© Stack Overflow or respective owner

Related posts about c#

Related posts about arrays